package hk.m4s.lr.repair.test.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import framework.common.Constant;
import framework.common.zanetwork.core.ResponseCallback;
import framework.utils.SharedPreferencesUtils;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.MyOrderModel;
import hk.m4s.lr.repair.test.model.MyWaiteOrderModel;
import hk.m4s.lr.repair.test.ui.user.MyoderEnValueActivity;
import hk.m4s.lr.repair.test.views.listview.InnerListView;
import okhttp3.Response;

/**
 * @author
 */
public class MyEnValueOderAdapter extends BaseAdapter {
    private MyoderEnValueActivity context;
    public List<MyOrderModel.ListBean> items;
    private List<MyWaiteOrderModel> myjiangLiModelList=new ArrayList<>();
    private ItemEnValueOderAdapter adapter;

    public MyEnValueOderAdapter(MyoderEnValueActivity context,
                                List<MyOrderModel.ListBean> items) {
        this.context = context;
        this.items = items;
    }

    public int getCount() {
        return 2;
    }

    public Object getItem(int position) {
        return getView(position, null, null);
    }

    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.list_item_my_envalue_order, null);
            holder = new ViewHolder();
            holder.order_shop_time = (TextView) convertView.findViewById(R.id.order_shop_time);
            holder.order_shop_totlaprice = (TextView) convertView.findViewById(R.id.order_shop_totlaprice);
            holder.cancle_order = (Button) convertView.findViewById(R.id.cancle_order);
            holder.header = (RelativeLayout) convertView.findViewById(R.id.header);
            holder.itemList = (InnerListView) convertView.findViewById(R.id.itemList);
            holder.order_shop_state = (TextView) convertView.findViewById(R.id.order_shop_state);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.cancle_order.setTag(position);
        holder.header.setTag(position);

//        MyOrderModel.ListBean model = items.get(position);
//
//        holder.header.setVisibility(View.VISIBLE);
//        holder.order_shop_state.setText("交易成功");
//        holder.cancle_order.setText("删除订单");
//        holder.order_shop_time.setText("订单编号:" + model.getOrder_number());
//        //holder.order_shop_totlaprice.setText(MoneyTool.getLocalMoney(model.getActual_money()));
//        if (model.getDetail() != null) {
//            myjiangLiModelList = new ArrayList<>();
//            for (MyOrderModel.ListBean.DetailBean detailBean : model.getDetail()) {
//                MyWaiteOrderModel waiteOrderModel = new MyWaiteOrderModel();
//                //waiteOrderModel.setTime(AppTools.getStrTime(detailBean.getAddTime()));
//                waiteOrderModel.setGoods_id(detailBean.getGoods_id());
//                waiteOrderModel.setId(detailBean.getId());
//                waiteOrderModel.setName(detailBean.getGoods_name());
//                waiteOrderModel.setPrice(detailBean.getGoods_price());
//                waiteOrderModel.setSize(detailBean.getGoods_color());
//                waiteOrderModel.setBuyNum(detailBean.getGoods_num());
//                waiteOrderModel.setState(detailBean.getStatus());
//                waiteOrderModel.setImg(detailBean.getImg());
//                waiteOrderModel.setEvaluate(detailBean.getEvaluate());
//                waiteOrderModel.setOrderId(model.getOrder_id());
//                waiteOrderModel.setDetails(model.getDetails());
//                myjiangLiModelList.add(waiteOrderModel);
//            }
            adapter = new ItemEnValueOderAdapter(context, myjiangLiModelList);
            holder.itemList.setAdapter(adapter);
//        }
//        holder.header.setOnClickListener(new View.OnClickListener()
//
//        {
//            @Override
//            public void onClick(View v) {
//                int num = (Integer) v.getTag();
//                MyOrderModel.ListBean model = items.get(num);
////                Intent aboutIntent = new Intent(context, LookEnOrderActivity.class);
////                aboutIntent.putExtra("orderId", model.getOrder_id());
////                aboutIntent.putExtra("statuts", "6");
////                if (model.getPayInfo().getOilMoney() != null) {
////                    aboutIntent.putExtra("oilMoney", model.getPayInfo().getOilMoney());
////                }
////                context.startActivity(aboutIntent);
//            }
//        });
//
//        holder.cancle_order.setOnClickListener(new View.OnClickListener()
//
//        {
//            @Override
//            public void onClick(View v) {
//                int num = (Integer) v.getTag();
////                MyOrderModel.ListBean myOrderModel = items.get(num);
////                deleteOrder(myOrderModel.getOrder_id());
//            }
//        });
        return convertView;
    }

    private class ViewHolder {
        TextView order_shop_time, order_shop_totlaprice, order_shop_state;
        Button cancle_order;
        private RelativeLayout header;
        InnerListView itemList;
    }

//    public void deleteOrder(String orderId) {
//        Map<String, Object> parmas = new HashMap<>();
//        parmas.put("device_type", Constant.device_type);
//        parmas.put("token", SharedPreferencesUtils.getSharedPreferences(Constant.token, ""));
//        parmas.put("userId", SharedPreferencesUtils.getSharedPreferences(Constant.userId, ""));
//        parmas.put("orderId", orderId);
//        AccountSerive.deleteOrder(context, parmas, new ResponseCallback<GoodsCarModel>() {
//            @Override
//            public void onSuccess(GoodsCarModel model) {
//
//            }
//
//            @Override
//            public void onError(Response response, int errorCode, String errorMsg, Exception e) {
//
//            }
//        });
//
//    }
}
